<template>
  <div class="background" id="login">
    <div style="margin-left: 600px;padding-top: 200px">
      <div style="margin-left:30px">
      <h1>供应链金融管理平台</h1>
      </div>
      <el-form :model="user" class="demo-form-inline">
        <el-row>
          <el-col :span="8">
            <el-form-item label="账号">
              <el-input v-model="user.username" placeholder="账号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="密码">
              <el-input v-model="user.password" placeholder="密码"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="onSubmit">登录</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
      this.$axios
        .post("http://localhost:8800/user/login", this.user)
        .then((resp) => {
          if (resp.data.code == 200) {
            console.log(resp.data.data);
            console.log(resp.data.message);
            console.log(window.localStorage);
            //用户名字
            window.localStorage.setItem("NAME", resp.data.data.username);
            //整个user信息
            window.localStorage.setItem("EMP", JSON.stringify(resp.data.data));
            //部门
            window.localStorage.setItem("DEP", resp.data.data.dep);
            //角色(包含权限)
            window.localStorage.setItem(
              "ROLE",
              JSON.stringify(resp.data.data.role)
            );
            this.$router.push("/main");
          } else if (resp.data.code == 500) {
            console.log(resp.data.message);
          }
        });
    },
  },
};
</script>

<style scoped>
.background {
  height: 720px;
  background-image: url("../images/4.jpg");
  background-size: cover;
}
</style>